{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Garimpagem de Dados\n",
    "\n",
    "## Aula 4 - Exercício de Classificação com kNN\n",
    "\n",
    "Aluno : Joel Oliveira Ribeiro ~ 371822"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Importando todas as bibliotecas para uso\n",
    "\n",
    "%matplotlib inline \n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from pandas import DataFrame\n",
    "import math \n",
    "from sklearn.neighbors import KNeighborsClassifier\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.preprocessing import normalize\n",
    "from sklearn import preprocessing"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Atualizando a função de classificação para medir na forma distância euclidiana para o pacote do scikit-learn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def someKNeighborsClassifier(k):\n",
    "    try:\n",
    "        return KNeighborsClassifier(n_neighbors=k, metric='euclidean')\n",
    "    except (k<=1) and (k%2==0) : # Para o algorítmo o k deve ser maior que um e ímpar\n",
    "        return ('Valor de k inválido, espera-se um k > 1 e ímpar')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Carregando o arquivo contendo o Banco de Dados requisitado"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   PassengerId  Survived  Pclass  \\\n",
      "0            1         0       3   \n",
      "1            2         1       1   \n",
      "2            3         1       3   \n",
      "3            4         1       1   \n",
      "4            5         0       3   \n",
      "\n",
      "                                                Name     Sex   Age  SibSp  \\\n",
      "0                            Braund, Mr. Owen Harris    male  22.0      1   \n",
      "1  Cumings, Mrs. John Bradley (Florence Briggs Th...  female  38.0      1   \n",
      "2                             Heikkinen, Miss. Laina  female  26.0      0   \n",
      "3       Futrelle, Mrs. Jacques Heath (Lily May Peel)  female  35.0      1   \n",
      "4                           Allen, Mr. William Henry    male  35.0      0   \n",
      "\n",
      "   Parch            Ticket     Fare Cabin Embarked  \n",
      "0      0         A/5 21171   7.2500   NaN        S  \n",
      "1      0          PC 17599  71.2833   C85        C  \n",
      "2      0  STON/O2. 3101282   7.9250   NaN        S  \n",
      "3      0            113803  53.1000  C123        S  \n",
      "4      0            373450   8.0500   NaN        S  \n"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv(\"train.csv\")\n",
    "print(df.head())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Selecionando e tratando a lista de features que deverão ser essências para a classificação "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Retirando features que de cara não parecem ser essências para a classificação\n",
    "df.drop(labels=['Name','Ticket','Cabin'], inplace=True, axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/joelribeiro/anaconda/lib/python3.6/site-packages/ipykernel_launcher.py:8: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  \n",
      "/Users/joelribeiro/anaconda/lib/python3.6/site-packages/ipykernel_launcher.py:12: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  if sys.path[0] == '':\n"
     ]
    }
   ],
   "source": [
    "# Transformando as features categoricas ['Sex' e 'Embarked') em numéricas\n",
    "df['Sex'] = pd.factorize(df['Sex'])[0]\n",
    "df['Embarked'] = pd.factorize(df['Embarked'])[0]\n",
    "\n",
    "# Tratando a feature 'Age' por conter valores do tipo NaN, substituindo pelo valor médio de todas as idades\n",
    "for i in range(len(df['Age'])):\n",
    "    if(math.isnan(df['Age'][i])):\n",
    "        df['Age'][i] = 0\n",
    "\n",
    "for i in range(len(df['Age'])):\n",
    "    if(df['Age'][i]==0):\n",
    "        df['Age'][i] = df['Age'].median()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "            Pclass       Sex       Age     SibSp     Parch      Fare  Embarked\n",
      "Pclass    1.000000 -0.131900 -0.356187  0.083081  0.018443 -0.549500  0.050992\n",
      "Sex      -0.131900  1.000000 -0.073377  0.114631  0.245489  0.182333  0.111249\n",
      "Age      -0.356187 -0.073377  1.000000 -0.232411 -0.155118  0.107554 -0.053111\n",
      "SibSp     0.083081  0.114631 -0.232411  1.000000  0.414838  0.159651 -0.058008\n",
      "Parch     0.018443  0.245489 -0.155118  0.414838  1.000000  0.216225 -0.076625\n",
      "Fare     -0.549500  0.182333  0.107554  0.159651  0.216225  1.000000  0.058462\n",
      "Embarked  0.050992  0.111249 -0.053111 -0.058008 -0.076625  0.058462  1.000000\n"
     ]
    }
   ],
   "source": [
    "#Matriz de Correlação\n",
    "corr = df.loc[:,'Pclass':].corr()\n",
    "print(corr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Separando o dataset em treino (75%) / teste (25%) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_train, X_test, y_train, y_test = train_test_split(normalize(df.loc[:,'Pclass':],norm='max'), df['Survived'], test_size=0.25)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Executando o classificador para 30 k's pulando de 4 em 4 e apresente todas as acurácias utilizando o dataset de validação (Qual o melhor k?) [plotar um gráfico com os resultados]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "results = []\n",
    "\n",
    "for k in range(5,120,4):\n",
    "    neigh = someKNeighborsClassifier(k)\n",
    "    neigh.fit(X_train, y_train)\n",
    "    \n",
    "    results.append([neigh.score(X_test,y_test),k])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0.70403587443946192, 5], [0.71300448430493268, 9], [0.70403587443946192, 13], [0.70403587443946192, 17], [0.71748878923766812, 21], [0.68161434977578472, 25], [0.66367713004484308, 29], [0.6547085201793722, 33], [0.64573991031390132, 37], [0.65022421524663676, 41], [0.64573991031390132, 45], [0.64125560538116588, 49], [0.65022421524663676, 53], [0.65022421524663676, 57], [0.6547085201793722, 61], [0.6547085201793722, 65], [0.6547085201793722, 69], [0.6547085201793722, 73], [0.65022421524663676, 77], [0.65022421524663676, 81], [0.6547085201793722, 85], [0.65022421524663676, 89], [0.6547085201793722, 93], [0.65022421524663676, 97], [0.65022421524663676, 101], [0.65022421524663676, 105], [0.65022421524663676, 109], [0.65022421524663676, 113], [0.65022421524663676, 117]]\n"
     ]
    }
   ],
   "source": [
    "print(results)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAD8CAYAAABw1c+bAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xt01eWd7/H3NxdygZAECJeEW0BQEQUlAlYUWmtFe9G2\nUwuKWsWh0HF6XTNjV9s158yZmTOtc6btrFNFDnipWB2rtjqtArZWqFYuQRHCTcM9EUgCQkIw9+/5\nY280xlx2kp3s2+e1Fkv277a/j+InP57f83sec3dERCRxJEW6ABER6V8KfhGRBKPgFxFJMAp+EZEE\no+AXEUkwCn4RkQSj4BcRSTAKfhGRBK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vZqOD+UUBFR+dHqSsJLLBzkEBX3KfMbDWx3y4I3DWVufum4OenCfwgiPW2\nfRo44O6V7t4IPAt8gthvV2sdtSXmM8XMvgZ8DrjVPxyD3+N2RWPwh7LwS0wwMyPQV7zb3f+j1a7n\ngTuCv7+DwEI2MaOTBXZiul0A7n4MOGJm5wc3XQPsIvbbdhiYbWaZwT+X1xB45hTr7Wqto7Y8Dyww\nszQzKwQmAZsjUF+PmNl8At2qX3D3s6129bxd7h51v4AbCDy93gf8INL19KIdcwj8dXM7sC346wZg\nKIFRB+8AfwCGRLrWXrRxHvC74O/jol3AdKA4+N/tt0BuPLQN+J/AHqAEeAxIi9V2AU8QeFbRSOBv\naYs7awvwg2Ce7AWuj3T93WxXKYG+/HMZsry37dKbuyIiCSYau3pERKQPKfhFRBKMgl9EJMEo+EVE\nEoyCX0QkwSj4RUQSjIJfRCTBKPhFRBLM/wc9qKuiZWxtXgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10d2ebc18>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "results = np.asarray(results)\n",
    "plt.plot(results[:,1],results[:,0])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.717488789238 21.0\n"
     ]
    }
   ],
   "source": [
    "for i in range(len(results)):\n",
    "    if(results[i,0]==max(results[:,0])):\n",
    "        max_Accuracie,max_k = [results[i,0],results[i,1]]\n",
    "\n",
    "print(max_Accuracie,max_k)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Executando o classificador para o melhor k encontrado utilizando o dataset de teste e apresentar um relatório da precisão "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "### ainda implementando ..."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
